// 2025/9/13
// H指数

class Solution {
public:
    int hIndex(vector<int>& citations) {
        vector<int> nums(1001, 0);
        for(auto n : citations)
        {
            nums[n]++;
        }
        int h = 0;
        for(h = nums.size() - 2; h >= 0; h--)
        {
            nums[h] += nums[h + 1];
            if(nums[h] >= h)
                break;
        }
        int n = citations.size();
        return min(n, h);
    }
};